package history.hot100;

// 98. 验证二叉搜索树:https://leetcode-cn.com/problems/validate-binary-search-tree/
// 题解：https://leetcode-cn.com/problems/validate-binary-search-tree/solution/yan-zheng-er-cha-sou-suo-shu-by-leetcode-solution/
public class LeetCode_98 {

    public boolean isValidBST(TreeNode root) {
        return isValidBST(root, Long.MIN_VALUE, Long.MAX_VALUE);
    }

    public boolean isValidBST(TreeNode node, long lower, long upper) {
        if (node == null) return true;
        if (node.val <= lower || node.val >=upper) return false;
        return isValidBST(node.left,lower,node.val) && isValidBST(node.right,node.val,upper);
    }
}

